package com.tuoyu.peopletest.view.custom;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tuoyu.peopletest.R;


/**
 * 标题有排序
 */
public class TitleOrderView extends RelativeLayout {

    private TextView tvTitleName;
    private ImageView ivUp;
    private ImageView ivDown;
    private View vOrderMain;

    public TitleOrderView(Context context) {
        super(context);
    }

    public TitleOrderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.view_title_order, this);
        tvTitleName = findViewById(R.id.tv_title_name);
        ivUp = findViewById(R.id.iv_up);
        ivDown = findViewById(R.id.iv_down);
        vOrderMain = findViewById(R.id.v_order);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TitleOrderView);
        if (typedArray != null) {
            String title = typedArray.getString(R.styleable.TitleOrderView_titleOrder_text);
            tvTitleName.setText(title);
            boolean aBoolean = typedArray.getBoolean(R.styleable.TitleOrderView_titleOrder_orderIsShow, true);
            if (!aBoolean) {
                vOrderMain.setVisibility(GONE);
            } else {
                vOrderMain.setVisibility(VISIBLE);
            }
            typedArray.recycle();
        }
    }

    public TitleOrderView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    public void setOrderUp() {
       ivUp.setImageResource(R.mipmap.sc_icon_arrorw_red);
       ivDown.setImageResource(R.mipmap.sc_iocn_arrorw_gray);
    }

    public void setOrderDown() {
        ivUp.setImageResource(R.mipmap.sc_iocn_arrorw_gray);
        ivDown.setImageResource(R.mipmap.sc_icon_arrorw_red);
    }

    public void setOrderRestore() {
        ivUp.setImageResource(R.mipmap.sc_iocn_arrorw_gray);
        ivDown.setImageResource(R.mipmap.sc_iocn_arrorw_gray);
    }
}
